<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Basic usage</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="swish.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.swish.html">Swish 函数</a></div>
 <div class="up"><a href="swish.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="swish.examples-basic" class="section">
  <h2 class="title">Basic usage</h2>
  <p class="para">
   <div class="example" id="example-4635">
    <p><strong>Example #1 Basic search query</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">try&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$swish&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Swish</span><span style="color: #007700">(</span><span style="color: #DD0000">"index.swish-e"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$results&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$swish</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"test&nbsp;OR&nbsp;text"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Found&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$results</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">hits</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&nbsp;results\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$results</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">nextResult</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</span><span style="color: #FF8000">//break&nbsp;after&nbsp;the&nbsp;first&nbsp;result<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">SwishException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Error:&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

   </div>
  </p>
  <p class="para">以上例程的输出类似于：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
Found 9 results
object(SwishResult)#3 (8) {
  [&quot;swishreccount&quot;]=&gt;
  int(1)
  [&quot;swishrank&quot;]=&gt;
  int(1000)
  [&quot;swishfilenum&quot;]=&gt;
  int(10)
  [&quot;swishdbfile&quot;]=&gt;
  string(13) &quot;index.swish-e&quot;
  [&quot;swishdocpath&quot;]=&gt;
  string(23) &quot;README.SUBMITTING_PATCH&quot;
  [&quot;swishtitle&quot;]=&gt;
  NULL
  [&quot;swishdocsize&quot;]=&gt;
  int(4557)
  [&quot;swishlastmodified&quot;]=&gt;
  int(1072136752)
}
</pre></div>
  </div>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="swish.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.swish.html">Swish 函数</a></div>
 <div class="up"><a href="swish.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
